package visiopuce.ui.providers;

import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;

import visiopuce.ui.tree.ITreeNode;

public class NavigationContentProvider implements IStructuredContentProvider,
		ITreeContentProvider {
	private boolean treeInputSet;

	public NavigationContentProvider() {
		super();
		this.treeInputSet = false;
	}
	
	public NavigationContentProvider(boolean treeInputSet) {
		super();
		this.treeInputSet = treeInputSet;
	}

	public Object[] getChildren(Object parentElement) {
		return ((ITreeNode) parentElement).getChildren().toArray();
	}

	public Object getParent(Object element) {
		return ((ITreeNode) element).getParent();
	}

	public boolean hasChildren(Object element) {
		return ((ITreeNode) element).hasChildren();
	}

	public Object[] getElements(Object inputElement) {
		Object[] tableau = null;

		if (treeInputSet) {

			tableau = getChildren(inputElement);
		} else {
			treeInputSet = true;
			tableau = new Object[] { inputElement };
		}

		return tableau;
	}

	public void dispose() {
	}

	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
	}
}